﻿function Login(){$("#login").animate({opacity:1,top:"49%"},200,function(){$(".userbox").show().animate({opacity:1},500);$("#login").animate({opacity:0,top:"60%"},500,function(){
$(this).fadeOut(200,function(){
$(".text_success").slideDown();
$("#successLogin").animate({opacity:1,height:"200px"},500)})})});
var urlDestino = $("#Id_URL_DESTINO").val();

setTimeout("window.location.href='"+ urlDestino +"'",3e3)}
function showError(a){$("#alertMessage").addClass("error").html(a).stop(true,true).show().animate({opacity:1,right:"0"},500)}
function showSuccess(a){$("#alertMessage").removeClass("error").html(a).stop(true,true).show().animate({opacity:1,right:"0"},500)}
function onfocus(){if($(window).width()>480){$(".tip input").tipsy({trigger:"focus",gravity:"w",live:true})}else{$(".tip input").tipsy("hide")}}
function hideTop(){$("#alertMessage").animate({opacity:0,right:"-20"},500,function(){$(this).hide()})}
function loading(a,b){$("body").append('<div id="overlay"></div><div id="preloader">'+a+"..</div>");if(b==1){$("#overlay").css("opacity",.1).fadeIn(
function(){$("#preloader").fadeIn()});return false}$("#preloader").fadeIn()}function unloading(){$("#preloader").fadeOut("fast",function(){$("#overlay").fadeOut()})}$(document).ready(
function () { onfocus(); $(".on_off_checkbox").iphoneStyle(); $(".tip a ").tipsy({ gravity: "sw" }); $("#login").show().animate({ opacity: 1 }, 2e3); $(".logo").show().animate({ opacity: 1, top: "33%" }, 800, function () { $(".logo").show().delay(1200).animate({ opacity: 1, top: "0%" }, 300, function () { $(".formLogin").animate({ opacity: 1, left: "0" }, 300); $(".userbox").animate({ opacity: 0 }, 200).hide() }) }) }); $(".userload").click(function (a) { $(".formLogin").animate({ opacity: 1, left: "0" }, 300); $(".userbox").animate({ opacity: 0 }, 200, function () { $(".userbox").hide() }) });
    $("#but_login").click(function (a) {
        ValidarUsuario();
    });
    $("#alertMessage").click(function () { hideTop() })


    $("#password").keypress(function (event) {
        var tecla_pulsada = (document.all) ? event.keyCode : event.which;
        if (tecla_pulsada == 13) {
            ValidarUsuario();
        }
    });


    function ValidarUsuario() {

        if (document.formLogin.username.value == "" || document.formLogin.password.value == "") {
            showError("Ingresar Usuario y Contraseña");
            $(".inner").jrumble({ x: 4, y: 0, rotation: 0 });
            $(".inner").trigger("startRumble");
            setTimeout('$(".inner").trigger("stopRumble")', 500); setTimeout("hideTop()", 5e3);
            return false
        }
        var opcion = 0;
        var url = $("#Id_URL").val();

        oUsuario = document.formLogin.username.value;
        oClave = document.formLogin.password.value;
        $.ajax({
            url: url,
            data: {
                usuario: oUsuario,
                contrasenia: oClave
            },
            type: "post",
            cache: false,
            success: function (data, textStatus, jqXHR) {
                var msj = jqXHR.responseText;
                if (msj == 1) {
                    hideTop();
                    loading("Verificando", 1);
                    setTimeout("unloading()", 2e3);
                    setTimeout("Login()", 2500)
                    opcion = 1;
                }
                if (msj == 2) {
                    showError("Usuario o contraseña incorrecto");
                    $(".inner").jrumble({ x: 4, y: 0, rotation: 0 });
                    $(".inner").trigger("startRumble");
                    setTimeout('$(".inner").trigger("stopRumble")', 500); setTimeout("hideTop()", 5e3);
                    opcion = 2;
                    return false
                }

            },
            error: function (jqXHR, status, error) {

            }
        });
        if (opcion == 1) {

        }
    }